package org.jeecg.modules.knowledgerelation.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.jeecg.modules.knowledgerelation.KnowledgeTreeVO;
import org.jeecg.modules.knowledgerelation.entity.KnowledgeRelation;
import org.jeecg.modules.knowledgerelation.mapper.KnowledgeRelationMapper;
import org.jeecg.modules.knowledgerelation.service.IKnowledgeRelationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * @Description: 知识之间的关系
 * @Author: jeecg-boot
 * @Date:   2020-12-20
 * @Version: V1.0
 */
@Service
public class KnowledgeRelationServiceImpl extends ServiceImpl<KnowledgeRelationMapper, KnowledgeRelation> implements IKnowledgeRelationService {
    @Autowired
    private KnowledgeRelationMapper knowledgeRelationMapper;
    @Override
    public IPage<KnowledgeRelation> mypage(Page<KnowledgeRelation> page, HttpServletRequest req) {
        List<KnowledgeRelation>list = knowledgeRelationMapper.queryKnowledgeInfo(page);
        return page.setRecords(list);
    }

    @Override
    public List<KnowledgeTreeVO> getTree() {

        return knowledgeRelationMapper.getTree();
    }

    @Override
    public List<KnowledgeTreeVO> getTreeByknowledge(String id) {
        List<KnowledgeTreeVO> treeByknowledge = knowledgeRelationMapper.getTreeByknowledge(id);
        AtomicInteger i = new AtomicInteger(1);
        treeByknowledge.forEach(item->item.setId(Integer.toString(i.getAndIncrement())));
        return treeByknowledge;
    }
}
